package com;

import com.mapper.CclassMapper;
import com.mapper.SstudentMapper;
import com.pojo.Cclass;
import com.pojo.Sstudent;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import util.MybatisUtils;

public class SstudentTest {
    @Test
    public void findSstudentByIdTest(){
        SqlSession session = MybatisUtils.getSession();
        SstudentMapper mapper = session.getMapper(SstudentMapper.class);
        Sstudent sstudent = mapper.selectSstudent(2);
        System.out.println(sstudent.toString());
        session.close();
    }
    @Test
    public void updateSstudentTest(){
        SqlSession session = MybatisUtils.getSession();
        Sstudent sstudent=new Sstudent();
        sstudent.setId(4);
        sstudent.setName("李雷");
        sstudent.setAge(21);
        SstudentMapper mapper = session.getMapper(SstudentMapper.class);
        int result = mapper.updateSstudent(sstudent);
        if(result>0){
            System.out.println("成功更新" + result + "条数据！");
        }else {
            System.out.println("更新数据失败");
        }
        System.out.println(sstudent.toString());
        session.commit();
        session.close();
    }
    @Test
    public void selectCclassByIdTest(){
        SqlSession session = MybatisUtils.getSession();
        CclassMapper mapper = session.getMapper(CclassMapper.class);
        Cclass cclass = mapper.selectByCclassId(2);
        System.out.println(cclass.toString());
        session.commit();
    }
}
